angular.module('mustache.directives', [])
	.directive('hideTabs',function($rootScope){
		return {
			restrict: 'A',
			link: function(scope, element, attributes) {
				scope.$on('$ionicView.beforeEnter', function() {
					scope.$watch(attributes.hideTabs, function(value){
						$rootScope.hideTabs = 'tabs-item-hide';
					});
				});
				scope.$on('$ionicView.beforeLeave', function() {
					scope.$watch(attributes.hideTabs, function(value){
						$rootScope.hideTabs = 'tabs-item-hide';
					});
					scope.$watch('$destroy',function(){
						$rootScope.hideTabs = false;
					})
				});
			}
		};
	})
	.filter('imgUrl', function(){
		return function(param){
			return 'http://static.hzxiansheng.com/' + param;
		}
	})
	.directive('buttonWidget', function(sendSms){
		"按钮指令";
		return {
			restrict: 'A',
			link: function(scope, element, attrs){
				var wait=90;
				function sendSmsTimer(){
					"use strict";
					if (wait == 0) {
						element.removeAttr('disabled').text("重新发送短信验证码");
						wait = 60;
					} else {
						element.attr('disabled', 'disabled').text(wait + "秒后重发验证码");
						wait--;
						setTimeout(function(){sendSmsTimer()}, 1000)
					}
				}
				switch(attrs.buttonWidget){
					case 'sms':
						"发送电信能力平台短信验证码按钮";
						element.bind('click', function(){
							sendSms.ctc(attrs.mobile, function(resp){
								if(resp.type.toLowerCase() == 'success') sendSmsTimer();
							}, attrs.ac);
						});
						break;
					case 'pnr':
						"发送汇付天下短信验证码按钮";
						break;
				}
			}
		}
	});